Skip to content

列出推理设备 - YoloListDevices

函数简介

列出当前机器上 YOLO 可选推理设备(CPU 与 Windows 显卡统一放在 Devices 数组)。返回的 Devices[].DeviceIndex 可直接作为 YoloLoadModel / YoloLoadModelEx 等接口的 inferenceDevice。设备语义详见 推理设备说明

接口名称

YoloListDevices

DLL 调用

long YoloListDevices(long ola);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 列出可见显卡,再按 DeviceIndex 加载模型
auto devicesJson = ola.YoloListDevices();
// 解析 Devices[].DeviceIndex / Type / SupportedBackends
long handle = ola.YoloLoadModelEx("models/yolov8n.onnx", "", "person|car", 1, 0, /*inferenceDevice*/ 0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
var devicesJson = ola.YoloListDevices();
// 解析 Devices[].DeviceIndex 后传入加载接口
long handle = ola.YoloLoadModelEx("models/yolov8n.onnx", "", "person|car", 1, 0, 0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
devices_json = ola.YoloListDevices()
# 解析 Devices[].DeviceIndex 后传入加载接口
handle = ola.YoloLoadModelEx("models/yolov8n.onnx", "", "person|car", 1, 0, 0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
var devicesJson = ola.YoloListDevices();
long handle = ola.YoloLoadModelEx("models/yolov8n.onnx", "", "person|car", 1, 0, 0);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
devicesJson := ola.YoloListDevices()
handle := ola.YoloLoadModelEx("models/yolov8n.onnx", "", "person|car", 1, 0, 0)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let devices_json = ola.yolo_list_devices();
cpp
var ola = com("OlaPlug.OlaSoft")
var devicesJson = ola.YoloListDevices()
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
devicesJson = ola.YoloListDevices()
text
.局部变量 ola, OLAPlug
ola.创建 ()
devicesJson = ola.YoloListDevices()
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var devicesJson = ola.YoloListDevices();
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
自动 devicesJson = ola.YoloListDevices()
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
auto devicesJson = ola.YoloListDevices();

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long devicesJsonPtr = YoloListDevices(instance);
if (devicesJsonPtr != 0) {
    char devicesJson[2048] = {0};
    GetStringFromPtr(devicesJsonPtr, devicesJson, sizeof(devicesJson));
    FreeStringPtr(devicesJsonPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long YoloListDevices(long ola);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);

long instance = CreateCOLAPlugInterFace();
long devicesJsonPtr = YoloListDevices(instance);
if (devicesJsonPtr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(devicesJsonPtr) + 1);
    GetStringFromPtr(devicesJsonPtr, sb, sb.Capacity);
    FreeStringPtr(devicesJsonPtr);
    string devicesJson = sb.ToString();
}
python
from ctypes import CDLL, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.YoloListDevices.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
devices_json_ptr = ola.YoloListDevices(instance)
if devices_json_ptr:
    buf = create_string_buffer(2048)
    ola.GetStringFromPtr(devices_json_ptr, buf, 2048)
    ola.FreeStringPtr(devices_json_ptr)
    devices_json = buf.value.decode("utf-8")

返回值

返回值说明
(返回值)长整数型:JSON 字符串指针;须 FreeStringPtr 释放。

返回 JSON 结构(PascalCase)

json
{
  "Success": true,
  "Devices": [
    {
      "DeviceIndex": -1,
      "Name": "CPU",
      "Type": "CPU",
      "InferenceDevice": "CPU",
      "SupportedBackends": ["Ncnn", "Onnx"],
      "Note": "YOLO 不会在多个物理 CPU/插槽之间做设备选择。inferenceDevice=-1 表示使用主机 CPU;TensorRT 不支持 CPU。"
    },
    {
      "DeviceIndex": 0,
      "Name": "Intel(R) UHD Graphics",
      "Type": "Intel",
      "VendorId": 32902,
      "DeviceId": 0,
      "Software": false,
      "SupportedBackends": ["Ncnn"],
      "InferenceDevice": "GPU0"
    },
    {
      "DeviceIndex": 1,
      "Name": "NVIDIA GeForce RTX 3080",
      "Type": "NVIDIA",
      "VendorId": 4318,
      "DeviceId": 8708,
      "Software": false,
      "CudaDeviceIndex": 0,
      "SupportedBackends": ["Ncnn", "TensorRt", "Onnx"],
      "InferenceDevice": "GPU1"
    }
  ]
}
字段说明
Devices[].DeviceIndex传给加载接口的 inferenceDevice(CPU=-1,GPU=0+);列表按该字段升序
Devices[].Name / Type设备名称与类型(CPU / NVIDIA / AMD / Intel / …)
Devices[].CudaDeviceIndex库内 NVIDIA 序号;仅 NVIDIA 有该字段。勿当作 inferenceDevice
Devices[].SupportedBackends该设备可用后端:Ncnn / TensorRt / Onnx
Devices[].Note补充说明(如 CPU 多插槽调度)

注意事项

项目说明
模块权限需要插件已开通 YOLO 模块权限(Reg、Login 的 FeatureList 中包含 YOLO 特性)。
设备语义详见 推理设备说明
释放内存返回的 JSON 字符串须调用 FreeStringPtr 释放。
TensorRT/ONNX须选择 Type=NVIDIASupportedBackendsTensorRt/OnnxDeviceIndex,否则创建模型失败。